<template>
  <div>
    <!--官网复制表格插件,更改要展示的信息-->
    <el-table
      :data="tableData"
      stripe
      style="width: 100%">
      <el-table-column
        prop="id"
        label="编号"
        width="180"
      >
      </el-table-column>

      <el-table-column
        prop="createTime"
        label="日期"
        width="180">
      </el-table-column>

      <el-table-column
        prop="name"
        label="姓名"
        width="180"
      >
      </el-table-column>

      <el-table-column
        prop="phone"
        label="电话"
        width="180"
      >
      </el-table-column>

      <el-table-column
        prop="email"
        label="邮箱"
        width="180"
      >
      </el-table-column>

      <el-table-column
        prop="address"
        label="地址" >
      </el-table-column>
    </el-table>
    <!--
      分页按钮
      因为:我们后面的分页按钮都需要从后端传过来的值.
      所以需要在script中创建这两个值,接收.ajax传过来的值
      然后通过:号在展示页面就是el-pagination标签中的这两个值进行接收展示
        @current-change   这句是给分页按钮的当前页进行绑定一个单击事件,如果这个值有改变
        那么就重新发送ajax请求,接收值是函数
    -->
    <el-pagination
      background
      align="right"

      :current-page="currentpage"
      :page-size="pagesize"

      :page-sizes="[5, 10, 15]"

      @current-change="gocurrent"
      layout="sizes,prev, pager, next"
      :total="total">
    </el-pagination>

  </div>
</template>

<script>
/* 引入axios
*  局部引入进行
* */
import axios from "axios"

export default {
  data () {
    return {
      tableData: [],
      currentpage:1,
      pagesize:10,
      total:0
    }
  },
  /* 钩子函数,页面加载完毕后就进行钩子函数发送请求*/
  mounted() {
    this.list()
  },
  methods: {
    gocurrent(currentpage){
      this.currentpage = currentpage;
      this.list()
    },

    /*
      发送请求到mock.js中获取数据
    * */
    list(){
      this.$http.get("/ueser/gethome",{"currentPage":this.currentpage,"pageSize":this.pagesize})
        .then(result =>{
          this.tableData = result.data.data;
          this.total = result.data.totals;
        })
        .catch(error =>{
          console.log(error);
          alert("系统繁忙,请稍后重试")
        })
    }
  }
}
</script>


<!-- Add "scoped" attribute to limit CSS to this component only -->
<style >

</style>
